package com.Shop.Center.service;

import com.Shop.Center.entity.Shopcar;
import com.Shop.Center.mapper.ShopcarMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ShopcarService {
    @Autowired
    ShopcarMapper shopcarMapper;
    public int add(long itemid,int count,long userid){
        Shopcar shopcar=new Shopcar();
        long id=new IdWorker().hashCode();
        shopcar.setCount(count);
        shopcar.setItemid(itemid);
        shopcar.setUserid(userid);
        shopcar.setId(id);
        return shopcarMapper.insert(shopcar);
    }
    public int delete(long id){
        return shopcarMapper.deleteById(id);
    }
    public List get(long userid){
        QueryWrapper<Shopcar> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userid",userid);
        return shopcarMapper.selectList(queryWrapper);
    }
}
